﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Finance.Data.Entities;

namespace Finance.Views
{
	internal partial class DocumentListItemView : UserControl
	{
		private IDocumentBase _document;

		public DocumentListItemView()
		{
			InitializeComponent();
		}

		public override ContextMenu ContextMenu
		{
			get
			{
				return base.ContextMenu;
			}
			set
			{
				panel1.ContextMenu = value;
				base.ContextMenu = value;
			}
		}

		public bool Selected
		{
			set { 
				BackColor = value ? Color.SteelBlue : Color.White;
				panel1.BackColor= value ? Color.SteelBlue : Color.White;
				_priceLabel.ForeColor = value ? Color.White : Color.Black;
				_productCategoryLabel.ForeColor = value ? Color.White : Color.Black;
				_contractorNameLabel.ForeColor = value ? Color.White : Color.Black;
			}
		}

		public IDocumentBase Document
		{
			set
			{
				_document = value;
				_contractorNameLabel.Text = value.ContractorName;
				_productCategoryLabel.Text = value.SubTypeName;
				_priceLabel.Text = value.Amount.ToString("G");
			}
			get { return _document; }
		}

		public object Data
		{
			get { return Document; }
			set
			{
				if(!(value is IDocumentBase))
					throw new Exception("The item should be IDocumentBase type.");

				Document = (IDocumentBase)value;
			}
		}

		private void panel1_MouseDown(object sender, MouseEventArgs e)
		{
			OnMouseDown(e);
		}

		private void panel1_MouseUp(object sender, MouseEventArgs e)
		{
			OnMouseUp(e);
		}
	}
}
